package commRedisService

import "gitee.com/fierce_wolf/go-fox-edge-common/commEntity"

type RedisAgileServiceManager struct {
	services map[string]*RedisAgileService
}

func (e *RedisAgileServiceManager) GetAgileService(entityType string) *RedisAgileService {
	ptr := e.services[entityType]
	if ptr == nil {
		e.services[entityType] = e.newRedisAgileService(entityType)

		return e.services[entityType]
	}

	return ptr
}

func (e *RedisAgileServiceManager) newRedisAgileService(entityType string) *RedisAgileService {
	_, err := commEntity.NewEntity(entityType)
	if err != nil {
		panic("实例化Entity失败:" + entityType)
	}

	redisAgileService := &RedisAgileService{}
	redisAgileService.operator.EntityType = entityType
	redisAgileService.agileMap = make(map[string]int64)

	return redisAgileService
}
